<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../react18/react.development.js"></script>
    <script src="../react18/react-dom.development.js"></script>
    <script src="../react18/babel.min.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        class Message extends React.Component{
            state = {
                opacity:1,
                timer:null,
            }
            componentDidMount(){
                let {opacity}=this.state;
                var timer = setInterval(()=>{
                    console.log(opacity);
                    opacity-=0.03;
                    if(opacity<=0){
                        opacity=1
                    }
                    this.setState({opacity:opacity})
                },100);
                this.setState({timer:timer})
            }
            render(){
                return (
            <div>
              <h2 style={{ opacity: this.state.opacity }}>
                React真的有点难,怎么办?????
              </h2>
            </div>
          );
            }
            componentWillUnmount(){
                const {timer}=this.state;
                clearInterval(timer);
            }
        }
        class App extends React.Component{
            state = {
                isStudyReact:true,
            };
            render(){
                const {isStudyReact} = this.state;
                return <div>
                    {isStudyReact?<Message />:""}
                    <button onClick={this.changeStudyState}>
                        {isStudyReact ? "我不学了!!!!" : "我决定还是学吧!!!!"}</button>
                    </div>
            }
            changeStudyState=()=>{
                const {isStudyReact}=this.state;
                this.setState({
                    isStudyReact:!isStudyReact
                })
            }
        }
        ReactDOM.createRoot(document.getElementById("app")).render(<App />);
    </script>
</body>
</html>